package pub.guoxin.oops.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.querydsl.core.annotations.QueryEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mongodb.morphia.annotations.Entity;
import pub.guoxin.oops.tidy.LocalDateTimeDeserializer;
import pub.guoxin.oops.tidy.LocalDateTimeSerializer;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * Created by guoxin on 17-10-18.
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@QueryEntity
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Communication extends BaseEntity<String> implements Serializable {

    private static final long serialVersionUID = -7235405143771551246L;
    /**
     * 设备串号
     */
    private String sn;
    /**
     * 电池电量
     */
    private Float batteryLevel;
    /**
     * 版本号
     */
    private Integer version;
    /**
     * 经度
     */
    private Float longitude;
    /**
     * 纬度
     */
    private Float latitude;
    /**
     * 时间戳
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime dateTime;

    public RealTimeCommunication realTime() {
        this.init();
        return new RealTimeCommunication(this);
    }
}
